package com.rgs.gateway.common.exception;

import com.rgs.gateway.common.enums.SystemErrorEnum;
import io.swagger.annotations.ApiModelProperty;

/**
 * @ProjectName: framework
 * @Package: com.meix.api.common.core.exception
 * @ClassName: ServiceException
 * @Author: cao
 * @Description:
 * @Date: 2023/11/7 11:32
 * @Version: 1.0
 */
public class ServiceException extends RuntimeException  {

    private static final long serialVersionUID = -3236631070156731497L;

    @ApiModelProperty(value = "处理结果code", required = true)
    private Integer code;
    @ApiModelProperty(value = "处理结果描述信息")
    private String message;

    public ServiceException(Integer errCode) {
        this.code = errCode;
        this.message = SystemErrorEnum.getmesg(errCode);
    }

    public ServiceException(String mesg) {
        this.code = SystemErrorEnum.SYSTEM_ERROR.getCode();
        this.message = mesg;
    }

    public ServiceException(int errCode, String mesg) {
        this.code = errCode;
        this.message = mesg;
    }

    public ServiceException(String errCode, String mesg) {
        try {
            this.code = Integer.parseInt(errCode);
        } catch (Exception e) {
            this.code = SystemErrorEnum.SYSTEM_ERROR.getCode();
        }
        this.message = mesg;
    }

    public ServiceException(SystemErrorEnum systemErrorType) {
        this.code = systemErrorType.getCode();
        this.message = systemErrorType.getMessage();
    }

    public ServiceException(SystemErrorEnum systemErrorType, String mesg) {
        this.code = systemErrorType.getCode();
        this.message = mesg;
    }

    public int getErrCode() {
        return code;
    }

    public String getmesg() {
        return message;
    }
}
